<template>
    <el-container class="container">
        <el-header class="header">
            <div class="header-left">电商管理平台</div>
            <div class="header-right">
                <span>{{ username }}</span>
                <el-dropdown @command="loginout">
                    <span class="el-dropdown-link">
                        <el-icon>
                            <arrow-down-bold />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item>退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>

            </div>
        </el-header>
        <el-container>
            <el-aside width="200px" class="aside">
                <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
                    default-active="1" text-color="#fff" router>
                    <el-sub-menu :index="firstMenu.id + ''" v-for="firstMenu in menus" :key="firstMenu.id">
                        <template #title>
                            <span>{{ firstMenu.title }}</span>
                        </template>
                        <el-menu-item-group>
                            <template v-for="(secondMenu, index) in firstMenu.children">
                                <el-menu-item :index="`/${firstMenu.name}/${secondMenu.name}`"
                                    v-if="secondMenu.hidden === 0" :key="index">{{ secondMenu.title }}</el-menu-item>
                            </template>
                        </el-menu-item-group>
                    </el-sub-menu>
                </el-menu></el-aside>
            <el-main class=" main">
               
                    <breadheader></breadheader>
                
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>
<script setup>
import { reactive, toRefs, watch, onMounted, getCurrentInstance } from 'vue';
import { useStore } from 'vuex'
import { delToken } from '../../utils/unit'
import { useRouter } from 'vue-router';
import breadheader from './components/breadheader.vue'
import { LOGIN_OUT } from '../../api/index'
const store = useStore()
const router = useRouter()
const { proxy } = getCurrentInstance() // 1.获取proxy实例
const state = reactive({
    username: store.state.userStore.username,
})
const menus = store.getters.getNewMenus
const { username } = toRefs(state)
const loginout = () => {
    proxy.$request({
        url: LOGIN_OUT,
        method: 'post',
    }).then((res) => {
        if (res.code === 200) {
            localStorage.clear('username')
            delToken()
            router.push('/login')
        }

    })

}
</script>
<style scoped lang="scss">
.container {
    width: 100%;
    height: 100%;
}

.header {
    background-color: #4682bf;
    display: flex;
    justify-content: space-between;

    .header-left {
        display: flex;
        align-items: center;
        color: #eeeeee;
        font-size: 26px;
    }

    .header-right {
        display: flex;
        align-items: center;
    }
}

.aside {
    background-color: #545c64;
}



.main {
    background-color: beige;
    padding: 0;
   
    overflow: auto;
}
</style>    